Skip to content

Add missing Debug derive to vec::IntoIter #580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2025

Conversation

zeenix
Copy link
Contributor

@zeenix zeenix commented Jun 10, 2025

No description provided.

Copy link
Contributor

@sosthene-nitrokey sosthene-nitrokey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would lead to undefined behaviour.

The vec field in the IntoIter struct is not in a valid state after iteration has begun. All elements before next have been "removed" from the Vec through unsafe code even though it's still there. All methods on IntoIter must take care to not read from them.

If you want a Debug implementation, you will need not to go through derive, but instead write a manual implementation. You can take a look at the Clone implementation to see how Debug could be implemented manually.

@sosthene-nitrokey
Copy link
Contributor

sosthene-nitrokey commented Jun 11, 2025

This is where Unsafe fields could come in handy in the future.

@zeenix
Copy link
Contributor Author

zeenix commented Jun 11, 2025

@sosthene-nitrokey Thanks for the review. PTALA. I was first going for a more verbose option (f.debug_struct("IntoIter").field("elements", &s).finish()) but then decided against it. I can change to something like that, if you like.

@zeenix zeenix force-pushed the add-debug branch 2 times, most recently from e5a9d1c to be1ad3a Compare July 22, 2025 18:37
@zeenix zeenix requested a review from sosthene-nitrokey July 22, 2025 18:44
@zeenix zeenix enabled auto-merge August 8, 2025 16:28
sgued
sgued previously approved these changes Aug 13, 2025
@zeenix
Copy link
Contributor Author

zeenix commented Aug 13, 2025

Rebased.

@zeenix zeenix added this pull request to the merge queue Aug 13, 2025
Merged via the queue into rust-embedded:main with commit 0c9508d Aug 13, 2025
21 checks passed
@zeenix zeenix deleted the add-debug branch August 13, 2025 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants